<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
    <!-- 注意Vue-resource依赖于vue -->
    <script src="./lib/vue-resource.js"></script>
</head>

<body>
    <div id="app">
        <input type="button" value="get请求" @click="requestGet()">
        <input type="button" value="post请求" @click="requestPost()">
        <input type="button" value="jsonp请求" @click="requestJsonp()">
    </div>
</body>
<script>
    // 配置全局根路径
    Vue.http.options.root = 'http://localhost:8080';
    // 全局配置emulateJSON为true
    Vue.http.options.emulateJSON = true;

    var vm = new Vue({
        el: "#app",
        data: {
            // 这里会有跨域的问题，因为我没有搭服务器 配置全局根路径是需要些相对路径
            // getUrl: '/demo/requestGet',
            // postUrl: '/demo/requestPost',
            // jsonpUrl: '/demo/requestJsonp'
            getUrl: 'demo/requestGet',
            postUrl: 'demo/requestPost',
            jsonpUrl: 'demo/requestJsonp'
        },
        methods: {
            requestGet() {
                this.$http.get(this.getUrl, {
                    emulateJSON: true
                }).then(response => {
                    console.log(response);
                }, response => {
                    // error callback
                });
            },
            requestPost() {
                this.$http.post(this.postUrl, {
                    emulateJSON: true
                }).then(response => {
                    console.log(response);
                }, response => {
                    // error callback
                });
            },
            requestJsonp() {
                this.$http.jsonp(this.jsonpUrl, {

                }).then(response => {
                    console.log(response);
                }, response => {
                    // error callback
                });
            }
        }
    });
</script>

</html>